<?php

require '../com.swiss.mooh.dao.impl/ImageContentDaoImpl.php';
require '../com.swiss.mooh.service/ImageContentServiceImpl.php';


$dispatcher = new ImageContentDaoImpl();
$imageContentService = new ImageContentServiceImpl($dispatcher);

$output_dir = "../../assets/images/uploads/images/";
$descID = $_GET['descID'];
if (isset($_FILES["myfile"])) {
    $ret = array();

    $error = $_FILES["myfile"]["error"];
    //You need to handle  both cases
    //If Any browser does not support serializing of multiple files using FormData() 
    if (!is_array($_FILES["myfile"]["name"])) { //single file
        $fileName = uniqid() . "_" . $_FILES["myfile"]["name"];
        move_uploaded_file($_FILES["myfile"]["tmp_name"], $output_dir . $fileName);
        $imageContentService->createNewImageContent(uniqid(), $output_dir . $fileName, $fileName, $descID, date('Y-m-d h:i:s a', time()));
        $ret[] = $fileName;
    }
    echo json_encode($ret);
}
